cmake_minimum_required(VERSION 3.10)

project(GrabImageWithTRT)

# 使用 C++11 标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# 寻找 OpenCV 包
find_package(OpenCV REQUIRED)

# 添加 TensorRT 支持
find_package(CUDA REQUIRED)

# 包含头文件的路径，包括 OpenCV、TensorRT 和自定义库的路径
include_directories(
    ${PROJECT_SOURCE_DIR}/include
    ${OpenCV_INCLUDE_DIRS}
    /usr/local/cuda/include # 根据您的 CUDA 安装调整
    ~/Documents/MVS_STD_V3.0.1_240629/MVS-3.0.1_aarch64_20240629/MVS/include
)

# 链接库的路径，使用环境变量
link_directories(
    $ENV{MVCAM_COMMON_RUNENV}/aarch64
    /usr/local/cuda/targets/aarch64-linux/lib # 根据您的 CUDA 安装调整
)

# 设置编译选项
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Ofast -Wfatal-errors")

# 添加可执行文件
add_executable(GrabImageWithTRT 
    main.cpp 
    camera_control.cpp 
    trt.cpp) # 假设您的 TensorRT 代码在 trt.cpp 中

# 链接库，包括 OpenCV 库、自定义库、TensorRT 库和 CUDA 库
target_link_libraries(GrabImageWithTRT
    ${OpenCV_LIBS}
    MvCameraControl
    pthread
    opencv_core
    opencv_highgui
    opencv_imgcodecs
    nvinfer # TensorRT 推理库
    cudart   # CUDA 运行时库
    nvonnxparser # TensorRT ONNX 解析器
)

# 指定运行时库的路径
set_target_properties(GrabImageWithTRT PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/
    INSTALL_RPATH "$ENV{MVCAM_COMMON_RUNENV}/aarch64"
    INSTALL_RPATH "/usr/local/cuda/targets/aarch64-linux/lib" # 根据您的 CUDA 安装调整
)

# 如果需要使用 CUDA 的静态运行时，取消下面一行的注释
# set_target_properties(GrabImageWithTRT PROPERTIES CUDA_USE_STATIC_CUDA_RUNTIME ON)